#include "C_DlgObjectCharacteriastics.h"

C_DlgObjectCharacteriastics::C_DlgObjectCharacteriastics(QWidget *parent, PbSObject* pObject)
	: QDialog(parent)
{
	ui.setupUi(this);
	if(pObject !=NULL)
		setWindowTitle(windowTitle() + "-" + QString::fromUtf8(pObject->name().c_str()));
	m_pWidgetSTReference = new C_WidgetObjectSTReference(parent, pObject);
	m_pWidgetSTReference->setIndex(0);
	m_vecWidget.push_back(m_pWidgetSTReference);
	m_pWidgetLocation = new C_WidgetObjectLocation(parent, pObject);
	m_pWidgetLocation->setIndex(1);
	m_vecWidget.push_back(m_pWidgetLocation);
	m_pWidgetMorphology = new C_WidgetObjectMorphology(parent, pObject);
	m_pWidgetMorphology->setIndex(2);
	m_vecWidget.push_back(m_pWidgetMorphology);
	m_pWidgetComposition = new C_WidgetObjectComposition(parent, pObject);
	m_pWidgetComposition->setIndex(3);
	m_vecWidget.push_back(m_pWidgetComposition);
	m_pWidgetAttribute = new C_WidgetObjectAttribute(parent, pObject);
	m_pWidgetAttribute->setIndex(4);
	m_vecWidget.push_back(m_pWidgetAttribute);
	m_pWidgetBehavior = new C_WidgetObjectBehavior(parent, pObject);
	m_pWidgetBehavior->setIndex(5);
	m_vecWidget.push_back(m_pWidgetBehavior);
	m_pWidgetRelation = new C_WidgetObjectRelation(parent, pObject);
	m_pWidgetRelation->setIndex(6);
	m_vecWidget.push_back(m_pWidgetRelation);

	connect(ui.listWidget, SIGNAL(currentRowChanged(int)),this,SLOT(onCurrentRowChanged(int)));

}

C_DlgObjectCharacteriastics::~C_DlgObjectCharacteriastics()
{
	for (int i = 0;i<m_vecWidget.size();i++)
	{
		delete m_vecWidget[i];
		m_vecWidget[i] = NULL;
	}
	m_vecWidget.clear();
}

void C_DlgObjectCharacteriastics::onCurrentRowChanged( int iCurrentRow )
{
	clearWidgets();
	QLayout* pLayout = layout();
	switch (iCurrentRow)
	{
	case 0:
		pLayout->addWidget(m_pWidgetSTReference);
		break;
	case 1:
		pLayout->addWidget(m_pWidgetLocation);
		break;
	case 2:
		pLayout->addWidget(m_pWidgetMorphology);
		break;
	case 3: 
		pLayout->addWidget(m_pWidgetComposition);
		break;
	case 4:
		pLayout->addWidget(m_pWidgetAttribute);
		break;
	case 5:
		pLayout->addWidget(m_pWidgetBehavior);
		break;
	case 6:
		pLayout->addWidget(m_pWidgetRelation);
		break;
	}
}

void C_DlgObjectCharacteriastics::clearWidgets()
{
	if(this->layout()->count() == 2)
	{
		QWidget* pWidget = this->layout()->itemAt(1)->widget();
		this->layout()->removeWidget(pWidget);
		pWidget->setParent(NULL);
	}
}
